use crate::src::src::binomial_heap::{binomial_heap_free, binomial_heap_new, binomial_heap_pop, binomial_heap_insert, binomial_heap_num_entries};
use crate::src::test::alloc_testing::{alloc_test_set_limit};
use crate::src::src::compare_int::{int_compare};
use crate::src::test::framework::{run_tests};
use crate::src::struct_and_type::{BinomialHeapType, BinomialHeapCompareFunc, BinomialHeap, _BinomialHeap, BinomialHeapValue, UnitTestFunction};
use ::libc;
extern "C" {
    
    
    
    
    
    
    
    
}
pub const BINOMIAL_HEAP_TYPE_MAX: BinomialHeapType = 1;
pub const BINOMIAL_HEAP_TYPE_MIN: BinomialHeapType = 0;
#[no_mangle]
pub static mut test_array_test_binomial_heap: [libc::c_int; 10000] = [0; 10000];
#[no_mangle]
pub unsafe extern "C" fn test_binomial_heap_new_free() {
    let mut heap: *mut BinomialHeap = 0 as *mut BinomialHeap;
    let mut i: libc::c_int = 0;
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        heap = binomial_heap_new(
            BINOMIAL_HEAP_TYPE_MIN,
            Some(
                int_compare
                    as unsafe extern "C" fn(
                        *mut libc::c_void,
                        *mut libc::c_void,
                    ) -> libc::c_int,
            ),
        );
        binomial_heap_free(heap);
        i += 1;
        i;
    }
    alloc_test_set_limit(0 as libc::c_int);
    assert!((binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    ))
        .is_null());
}
#[no_mangle]
pub unsafe extern "C" fn test_binomial_heap_insert() {
    let mut heap: *mut BinomialHeap = 0 as *mut BinomialHeap;
    let mut i: libc::c_int = 0;
    heap = binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        test_array_test_binomial_heap[i as usize] = i;
        assert!(binomial_heap_insert(
            heap,
            &mut *test_array_test_binomial_heap.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinomialHeapValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    assert!(binomial_heap_num_entries(heap) == 10000 as libc::c_int as libc::c_uint);
    alloc_test_set_limit(0 as libc::c_int);
    assert!(binomial_heap_insert(heap, &mut i as *mut libc::c_int as BinomialHeapValue)
        == 0 as libc::c_int);
    binomial_heap_free(heap);
}
#[no_mangle]
pub unsafe extern "C" fn test_min_heap_test_binomial_heap() {
    let mut heap: *mut BinomialHeap = 0 as *mut BinomialHeap;
    let mut val: *mut libc::c_int = 0 as *mut libc::c_int;
    let mut i: libc::c_int = 0;
    heap = binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        test_array_test_binomial_heap[i as usize] = i;
        assert!(binomial_heap_insert(
            heap,
            &mut *test_array_test_binomial_heap.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinomialHeapValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    i = -(1 as libc::c_int);
    while binomial_heap_num_entries(heap) > 0 as libc::c_int as libc::c_uint {
        val = binomial_heap_pop(heap) as *mut libc::c_int;
        assert!(*val == i + 1 as libc::c_int);
        i = *val;
    }
    val = binomial_heap_pop(heap) as *mut libc::c_int;
    assert!(val.is_null());
    binomial_heap_free(heap);
}
#[no_mangle]
pub unsafe extern "C" fn test_max_heap_test_binomial_heap() {
    let mut heap: *mut BinomialHeap = 0 as *mut BinomialHeap;
    let mut val: *mut libc::c_int = 0 as *mut libc::c_int;
    let mut i: libc::c_int = 0;
    heap = binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MAX,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        test_array_test_binomial_heap[i as usize] = i;
        assert!(binomial_heap_insert(
            heap,
            &mut *test_array_test_binomial_heap.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                as BinomialHeapValue,
        ) != 0 as libc::c_int);
        i += 1;
        i;
    }
    i = 10000 as libc::c_int;
    while binomial_heap_num_entries(heap) > 0 as libc::c_int as libc::c_uint {
        val = binomial_heap_pop(heap) as *mut libc::c_int;
        assert!(*val == i - 1 as libc::c_int);
        i = *val;
    }
    val = binomial_heap_pop(heap) as *mut libc::c_int;
    assert!(val.is_null());
    binomial_heap_free(heap);
}
unsafe extern "C" fn generate_heap() -> *mut BinomialHeap {
    let mut heap: *mut BinomialHeap = 0 as *mut BinomialHeap;
    let mut i: libc::c_int = 0;
    heap = binomial_heap_new(
        BINOMIAL_HEAP_TYPE_MIN,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> libc::c_int,
        ),
    );
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        test_array_test_binomial_heap[i as usize] = i;
        if i != 10000 as libc::c_int / 2 as libc::c_int {
            assert!(binomial_heap_insert(
                heap,
                &mut *test_array_test_binomial_heap.as_mut_ptr().offset(i as isize) as *mut libc::c_int
                    as BinomialHeapValue,
            ) != 0 as libc::c_int);
        }
        i += 1;
        i;
    }
    return heap;
}
unsafe extern "C" fn verify_heap(mut heap: *mut BinomialHeap) {
    let mut num_vals: libc::c_uint = 0;
    let mut val: *mut libc::c_int = 0 as *mut libc::c_int;
    let mut i: libc::c_int = 0;
    num_vals = binomial_heap_num_entries(heap);
    assert!(num_vals == (10000 as libc::c_int - 1 as libc::c_int) as libc::c_uint);
    i = 0 as libc::c_int;
    while i < 10000 as libc::c_int {
        if !(i == 10000 as libc::c_int / 2 as libc::c_int) {
            val = binomial_heap_pop(heap) as *mut libc::c_int;
            assert!(*val == i);
            num_vals = num_vals.wrapping_sub(1);
            num_vals;
            assert!(binomial_heap_num_entries(heap) == num_vals);
        }
        i += 1;
        i;
    }
}
unsafe extern "C" fn test_insert_out_of_memory() {
    let mut heap: *mut BinomialHeap = 0 as *mut BinomialHeap;
    let mut i: libc::c_int = 0;
    i = 0 as libc::c_int;
    while i < 6 as libc::c_int {
        heap = generate_heap();
        alloc_test_set_limit(i);
        test_array_test_binomial_heap[(10000 as libc::c_int / 2 as libc::c_int)
            as usize] = 10000 as libc::c_int / 2 as libc::c_int;
        assert!(binomial_heap_insert(
            heap,
            &mut *test_array_test_binomial_heap
                .as_mut_ptr()
                .offset((10000 as libc::c_int / 2 as libc::c_int) as isize)
                as *mut libc::c_int as BinomialHeapValue,
        ) == 0 as libc::c_int);
        alloc_test_set_limit(-(1 as libc::c_int));
        verify_heap(heap);
        binomial_heap_free(heap);
        i += 1;
        i;
    }
}
#[no_mangle]
pub unsafe extern "C" fn test_pop_out_of_memory() {
    let mut heap: *mut BinomialHeap = 0 as *mut BinomialHeap;
    let mut i: libc::c_int = 0;
    i = 0 as libc::c_int;
    while i < 6 as libc::c_int {
        heap = generate_heap();
        alloc_test_set_limit(i);
        assert!((binomial_heap_pop(heap)).is_null());
        alloc_test_set_limit(-(1 as libc::c_int));
        binomial_heap_free(heap);
        i += 1;
        i;
    }
}
static mut tests_test_binomial_heap: [UnitTestFunction; 7] = unsafe {
    [
        Some(test_binomial_heap_new_free as unsafe extern "C" fn() -> ()),
        Some(test_binomial_heap_insert as unsafe extern "C" fn() -> ()),
        Some(test_min_heap_test_binomial_heap as unsafe extern "C" fn() -> ()),
        Some(test_max_heap_test_binomial_heap as unsafe extern "C" fn() -> ()),
        Some(test_insert_out_of_memory as unsafe extern "C" fn() -> ()),
        Some(test_pop_out_of_memory as unsafe extern "C" fn() -> ()),
        None,
    ]
};
unsafe fn main_0_test_binomial_heap(
    mut argc: libc::c_int,
    mut argv: *mut *mut libc::c_char,
) -> libc::c_int {
    run_tests(tests_test_binomial_heap.as_mut_ptr());
    return 0 as libc::c_int;
}
pub fn main_test_binomial_heap() {
    let mut args: Vec::<*mut libc::c_char> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    unsafe {
        ::std::process::exit(
            main_0_test_binomial_heap(
                (args.len() - 1) as libc::c_int,
                args.as_mut_ptr() as *mut *mut libc::c_char,
            ) as i32,
        )
    }
}
